home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / ctimer / ctimer1 / ctimer1.s next >
Encoding:
Text File  |  1995-11-05  |  6.5 KB  |  309 lines

  1. ;  Record:   word  name      program uses a linked list of these
  2. ;            int   visits    2
  3. ;            int   ecount    6
  4. ;            int   ehor      $A
  5. ;            int   evert     $E
  6. ;            int   shor/vert $12
  7. ;            int   scount    $16
  8. ;            APTR  *next     $1A
  9.  
  10.         OPT ALINK
  11.  
  12.     XDEF   _Ctime,_Cend,_Creport
  13.     XREF   _printf,_stdout
  14.  
  15. _Cinit    
  16.      LEA     server,A3
  17.      MOVE.B  #2,8(A3)
  18.      MOVE.B  #0,9(A3)
  19.      MOVE.L  #count,$E(A3)
  20.      MOVE.L  #name,$A(A3)
  21.      MOVE.L  #VertBServer,$12(A3)       
  22.      MOVEQ.L #5,D0
  23.      MOVE.L  A3,A1 
  24.      MOVE.L  4,A6
  25.      JSR     -168(A6)          AddIntServer
  26.  
  27.      LEA     dosname,A1
  28.      MOVE.L  4,A6
  29.      JSR     -408(A6)
  30.      MOVE.L  d0,DOSBase
  31.      BNE.W   record
  32.      BSR.W   clear
  33.      MOVE.L  #1,abort
  34.      BRA.W   go
  35. record
  36.      MOVE.L  #$1E,D0
  37.      MOVE.L  #$10001,D1
  38.      MOVE.L  4,A6
  39.      JSR     -198(A6)         Alocate memory for first record    
  40.      MOVE.L  D0,first
  41.      BNE.W   outfh
  42.      BRA.W   clear
  43.      MOVE.L  #1,abort
  44.      BRA.W   go
  45. outfh   
  46.      TST.L   _stdout
  47.      BEQ.B   nooutput
  48.      MOVE.L  _stdout,outputfile
  49.      BRA.B   go
  50. nooutput
  51.      MOVE.L  DOSBase,A6
  52.      JSR     -60(A6)
  53.      MOVE.L  D0,outputfile
  54.      BNE.W   go
  55.      BSR.W   clear
  56.      MOVE.L  #1,abort
  57. go
  58.      RTS
  59.  
  60. Cclose
  61.      MOVE.L  #5,D0
  62.      LEA     server,A1
  63.      MOVE.L  4,A6
  64.      JSR     -174(A6)          RemIntServer
  65.      RTS
  66.  
  67.  
  68. VertBServer:
  69.              movem.l   D1-D3/A6,-(A7)
  70.              move.l    A1,A0
  71.              addq.l    #1,(A0)
  72.              MOVEM.L   (A7)+,D1-D3/A6
  73.              rts
  74.  
  75. _Ctime   
  76.        LINK      A5,#0
  77.        MOVEM.L   d1-d7/a1-a6,-(A7)
  78.        MOVE.W    10(A5),D3
  79.        TST.L     primo
  80.        BNE.B     next
  81.        BSR.W     _Cinit
  82.        MOVE.L    #1,primo 
  83. next
  84.        TST.L     abort
  85.        BNE.W     quit1
  86.        MOVE.L    first,A2
  87. loop
  88.        MOVE.W    (A2),D0
  89.        CMP.W     D3,D0
  90.        BEQ.B     found
  91.        TST.L     $1A(A2)
  92.        BEQ.B     new_record
  93.        MOVE.L    $1A(A2),A2
  94.        BRA.B     loop
  95.  
  96. new_record 
  97.        MOVE.L    #$1E,D0
  98.        MOVE.L    #$10001,D1
  99.        MOVE.L    4,A6
  100.        JSR       -198(A6)      alloc next record
  101.        MOVE.L    D0,$1A(A2)
  102.        BNE.B     OK
  103.        BSR.W     clear
  104.        MOVE.L    #1,abort
  105.        BRA.B     quit1
  106. OK
  107.        MOVE.L    D0,A2
  108.        MOVE.W    D3,(A2)
  109. found
  110.        ADD.L     #1,2(A2)           visits
  111.        MOVE.L    $DFF004,$12(A2)    start hor/vert
  112.        MOVE.L    count,$16(A2)      VertB counts 
  113. quit1
  114.        MOVEM.L   (A7)+,d1-d7/a1-a6
  115.        UNLK      A5
  116.        RTS
  117.        
  118. _Cend
  119.        LINK      A5,#0
  120.        MOVEM.L   d1-d7/a1-a6,-(A7)
  121.        TST.L     abort
  122.        BNE.W     quit2
  123.        MOVE.L    $DFF004,D4
  124.        MOVE.L    count,D5           new count
  125.        AND.L     #$0001FFFF,D4      new hor/vert
  126.        MOVE.W    10(A5),D3
  127.        MOVE.L    first,A2
  128. loop2
  129.        MOVE.W    (A2),D2
  130.        CMP.W     D3,D2
  131.        BEQ.B     found2
  132.        TST.L     $1A(A2)
  133.        BEQ.B     quit2
  134.        MOVE.L    $1A(A2),A2
  135.        BRA.B     loop2
  136. found2
  137.        MOVEQ.L   #0,D0
  138.        MOVE.B    D4,D0              new hor
  139.        LSR.L     #8,D4
  140.        MOVEQ.L   #0,D1
  141.        MOVE.W    D4,D1              new vert
  142.        TST.L     D0
  143.        BNE.B     old
  144.        ADDQ.L    #1,D1
  145. old
  146.        MOVE.L    $12(A2),D4 
  147.        AND.L     #$0001FFFF,D4      old hor/vert
  148.        MOVEQ.L   #0,D2
  149.        MOVE.B    D4,D2              old hor
  150.        LSR.L     #8,D4 
  151.        MOVEQ.L   #0,D3
  152.        MOVE.W    D4,D3              old vert
  153.        TST.L     D2
  154.        BNE.B     sum
  155.        ADDQ.L    #1,D3
  156. sum
  157.        SUB.L     D2,D0
  158.        ADD.L     D0,$A(A2)          diff hor
  159.        SUB.L     D3,D1
  160.        ADD.L     D1,$E(A2)          diff vert
  161.        SUB.L     $16(A2),D5
  162.        ADD.L     D5,6(A2)           diff count
  163. quit2
  164.        MOVEM.L   (A7)+,d1-d7/a1-a6
  165.        UNLK      A5
  166.        RTS
  167.        
  168. _Creport
  169.     LINK    A5,#-$18
  170.     MOVEM.L    A3/A4/A6,-(A7)
  171.         JSR    Cclose
  172.     TST.L   abort
  173.         BNE.W   go2
  174.         LEA     mathname,A1
  175.         MOVE.L  4,A6
  176.         JSR     -408(A6)
  177.         MOVE.L  d0,MATHBase
  178.         MOVE.L  first,A4
  179. loop3
  180.           CMP.L    #0,A4
  181.     BEQ.W    exit
  182.     MOVEA.L    MATHBase,A6
  183.         MOVE.L    6(A4),D0
  184.     JSR    -$24(A6)         float
  185.     MOVE.L    #$9C40004F,D1
  186.     JSR    -$4E(A6)         mult
  187.     MOVE.L    D0,-$4(A5)  
  188.     MOVE.L    $E(A4),D0
  189.     JSR    -$24(A6)         float
  190.     MOVE.L    #$82000047,D1
  191.     JSR    -$4E(A6)         mult 
  192.     MOVE.L    -$4(A5),D1
  193.     JSR    -$42(A6)         add
  194.     MOVE.L    D0,-$4(A5)
  195.     MOVE.L    $A(A4),D0
  196.     JSR    -$24(A6)         float
  197.     MOVE.L    #$8F5C293F,D1
  198.     JSR    -$4E(A6)         mult
  199.     MOVE.L    -$4(A5),D1
  200.     JSR    -$42(A6)         add
  201.     JSR     -$1E(A6)         SPfix - convert to hex
  202.  
  203.         DIVU.   #$3E8,D0
  204.         MOVE.W  D0,D2            msecs
  205.         EXT.L   D2
  206.         SWAP    D0
  207.         MOVE.W  D0,D3            micros 
  208.         EXT.L   D3
  209.         DIVU    #$3E8,D2
  210.         MOVE.W  D2,D4            secs
  211.         EXT.L   D4
  212.         SWAP    D2
  213.         MOVE.W  D2,D5            msecs 
  214.         EXT.L   D5  
  215.  
  216.         LEA     format,A0
  217.         LEA     datastore,A1
  218.         MOVE.W  0(A4),D0
  219.         EXT.L   D0
  220.         MOVE.L  D0,(A1)
  221.         MOVE.L  2(A4),4(A1)
  222.         MOVE.L  D4,8(A1)
  223.         MOVE.L  D5,$C(A1)
  224.         MOVE.L  D3,$10(A1)
  225.         LEA     code,A2
  226.         LEA     output,A3
  227.         MOVE.L  4,A6
  228.         JSR     -522(A6)         RawDoFmt        
  229.  
  230.         MOVE.L  A3,A2
  231. next2
  232.         TST.B   (A2)+
  233.         BNE.B   next2
  234.         SUBQ.L  #1,A2
  235.         SUBA.L  A3,A2
  236.  
  237.         MOVE.L  outputfile,D1
  238.         MOVE.L  A3,D2
  239.         MOVE.L  A2,D3
  240.         MOVE.L  DOSBase,A6
  241.         JSR     -48(A6)
  242.  
  243.         MOVEA.L    $1A(A4),A4       next record  
  244.     BRA    loop3
  245. exit
  246.         BSR.B   clear
  247. go2
  248.     MOVEM.L    (A7)+,A3/A4/A6
  249.     UNLK    A5
  250.     RTS
  251.  
  252. code
  253.         MOVE.B  D0,(A3)+
  254.         RTS
  255.  
  256. clear
  257.     MOVEM.L    A1-A6,-(A7)
  258.  
  259.         TST.L   first
  260.         BEQ.B   math
  261.         MOVE.L  first,A1
  262. loop4
  263.         MOVE.L  $1A(A1),A2
  264.         MOVE.L  #$20,D0
  265.         MOVE.L  4,A6
  266.         JSR     -210(A6)
  267.         MOVEA.L A2,A1
  268.         CMP.L   #0,A1
  269.         BNE.B   loop4
  270. math
  271.         TST.L   MATHBase
  272.         BEQ.B   realclear
  273.         MOVE.L  MATHBase,A1
  274.         MOVE.L  4,A6
  275.         JSR     -414(A6)
  276. realclear
  277.     MOVEM.L    (A7)+,A1-A6
  278.     RTS
  279.  
  280. datastore dc.l  0,0,0,0,0,0
  281. output    dc.l  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  282.               
  283. format    dc.b  'Function %ld: Visits %ld  secs %ld  msecs %ld  micros %ld',10,0
  284.   EVEN
  285.  
  286. name      dc.b 'VBlank_Count',0
  287.   EVEN
  288. dosname   dc.b 'dos.library',0
  289.   EVEN 
  290. mathname  dc.b 'mathffp.library',0
  291.   EVEN 
  292. server    dc.b 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  293. count     dc.l 0
  294. DOSBase   dc.l 0
  295. MATHBase  dc.l 0
  296. primo     dc.l 0
  297. first     dc.l 0 
  298. outputfile dc.l 0
  299. abort     dc.l 0
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.